// 过滤出当前用户的权限
import { constantRoutes, asyncRoutes } from '@/router/index'

const state = {
  routes: []
}
const mutations = {
  getRoutes(state, routes) {
    // 静态路由拼接,当前用户权限的路由
    state.routes = [...constantRoutes, ...routes]
  }
}
const actions = {
  filterRoutes(store, menus) {
    // console.log(444, asyncRoutes, menus)
    const result = asyncRoutes.filter(item => {
      if (menus.indexOf(item.name) !== -1) {
        return item
      }
    })
    store.commit('getRoutes', result)
    // console.log(66666, result)
  }
}

// 导出
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
